<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<!DOCTYPE html>
<html lang="zh-CN">
	<head> 
    <meta charset="UTF-8">
    <%@ include file="/WEB-INF/views/include/head.jsp"%>
    <link rel="stylesheet" href="${ctxStatic}/css/common_erp.css">
    <link rel="stylesheet" href="${ctxStatic}/css/layerSm.css">
    <script src="${ctxStatic}/dateCalendar/WdatePicker.js"></script>
    <c:set var="statusWaitSample" value="<%=ResourcesUtil.getConfig(\"specimen_production_status_wait_sample\")%>" />
    <c:set var="statusWaitAccept" value="<%=ResourcesUtil.getConfig(\"specimen_production_status_wait_accept\")%>" />
    <c:set var="statusWaitDone" value="<%=ResourcesUtil.getConfig(\"specimen_production_status_done\")%>" />
    <script>
    var statusWaitSample = "${statusWaitSample}";
    var statusWaitAccept = "${statusWaitAccept}";
    var statusWaitDone = "${statusWaitDone}";
	$(document).ready(function(){
        // 下拉选框带搜索功能
        $("#makeId,#samId").select2();
        
        $("#backBtn").click(function(){
            $("#showHtml").removeClass("showHtml");
            $("#confirmPage").css("display","none");
            $("#editPage").css("display","block");
            return false;
        });
        
        // 画面制御
        if($("#sampleProductionStatus").val() == statusWaitSample){  //待打样
        	$("#showHtmlTemplate").addClass("showHtml");        	
        }else if(($("#sampleProductionStatus").val() == statusWaitDone)){  //待验收
        	$("#showHtml").addClass("showHtml");
        	$("#confirmBtn").hide();
        }
	});
	
	Math.formatFloat = function(f, digit) { 
		var s = f;
		//判断字符串是否为数字     //判断正整数 /^[1-9]+[0-9]*]*$/  
		var numberVerification = /^[0-9]+.?[0-9]*$/;   
		if (numberVerification.test(s)){
			s = parseFloat((s + "").replace(/[^\d\.-]/g, "")).toFixed(digit) + "";  
		}else{
			s = 0;
		}
	    return parseFloat(s); 
	}
	
    // 成本单价
    function addCost(){
    	var materialCost = parseFloat(($("#sampleMaterialCost").val()).replace(/,/g,''));
    	var mandayCost = parseFloat(($("#sampleMandayCost").val()).replace(/,/g,''));
    	var otherCost = parseFloat(($("#sampleOtherCost").val()).replace(/,/g,''));
        var tempSum = Math.formatFloat((materialCost+mandayCost),2);
        tempSum = Math.formatFloat((tempSum + otherCost),2);
    	$("#sampleCost").val(tempSum);
    	formatMoney(sampleCost);
    }
    
    //保存方法
    var checkForm={
        t:null,
        check:function(t){
            this.t=t;
            // 表单验证
            $("#inputForm").validate();
            if($("#inputForm").valid()){
                $("#showHtml").addClass("showHtml");
                $("#confirmPage").css("display","block");
                $("#editPage").css("display","none");
            }
        }
    }
    
    var saveForm={
    		s:null,
            t:null,
            save:function(s,t){
                $(t).attr("disabled",true);
                this.s=s;
                this.t=t;
                if(saveForm.s==0){
                	$("#sampleProductionStatus").val(statusWaitAccept);
                    //如果完了日null 则等于''
                   if($("#sampleEndDate").val()=="" || $("#sampleEndDate").val()==null){
                           layer.msg('<spring:message code="pecimenProduct_pleaseInputSampleEndDate"/>', {time:1000});
                           $("#backBtn").click();
                           $(t).attr("disabled",false);
                           return;
                   }
                } 
                // 格式化，去除逗号
                formUnFormat($("#inputForm"));
         	    var params = $("#inputForm").serialize();
                $.post("${ctx}/specimen/production/save",params,function(result){
               	 // 提示信息
                    tipParent(result.message);
                    // 返回状态
                    if(result.statusCode==STATUSCODEOK){
                          window.parent.frames[0].searchListForm();
                          closeWin(); 
                      }else{
                          $(saveForm.t).attr("disabled",false);
                      }
                },'json');
            } 
       }
    
    jQuery.validator.addMethod("validateEndDate", function(value, element,param) {
        var startDate = jQuery(param).val();
        if(startDate=='' || this.optional(element)){
        	return true;
        }
        var date1=new Date(startDate.replace("-", "/").replace("-", "/"));  
        var date2=new Date(value.replace("-", "/").replace("-", "/"));  
        return date1 <= date2; 
    	
    }, "<spring:message code="pecimenProduct_StartDate_Over"/>");
    
    
    </script>
    </head>
	<body>
	<div id="editPage" class="layerHeader clearfix">
		<p class="headerTitle"><spring:message code="specimenProduct_edit_title"/></p>
	    <div class="headerButton clearfix">
	    	<shiro:hasPermission name="specimen:production:edit">
	        <button id="confirmBtn" type="button" onclick="checkForm.check(this)"><spring:message code="btn_ok"/></button>
	        </shiro:hasPermission> 
	        <button type="button" onclick="closeWin()"><spring:message code="btn_cancle"/></button>
	    </div>
	</div>

	<form id="inputForm" method="post" >
	<c:set value="<%=ResourcesUtil.getConfig(\"specimen_production_status_wait_template\")%>" var="statusWaitTemplate" />
	<input type="hidden" id="id" name="id" value="${specimenProduction.id}">
	<!-- 样品生产状态 -->
	<input type="hidden" id="sampleProductionStatus" name="sampleProductionStatus" value="${specimenProduction.sampleProductionStatus}">

	<!-- 确认页面head部 -->
	<div id="confirmPage" class="layerHeader clearfix" style="display:none">
		<p class="headerTitle"><spring:message code="specimenProduct_edit_title"/></p>
	    <div class="headerButton clearfix">
	        <shiro:hasPermission name="specimen:production:edit">
	        <c:if test="${specimenProduction.sampleProductionStatus != statusWaitTemplate}">
	           <button type="button" onclick="saveForm.save(0,this)"><spring:message code="pecimenProduct_btn_submit"/></button>
	        </c:if>
	        </shiro:hasPermission>
	        <shiro:hasPermission name="specimen:production:edit">
	        <button type="button" onclick="saveForm.save(1,this)"><spring:message code="common_save"/></button>
	        </shiro:hasPermission>
	        <button type="button" id="backBtn"><spring:message code="btn_cancle"/></button>
	    </div>
	</div>
	
	<div id="showHtml">
	<div class="tabBoxSm">
    	<div class="tabSm smOrderBox">
	        <p class="title"><spring:message code="pecimenProduct_tabpage_title"/></p>
	        <div id="showHtmlTemplate">
	        <shiro:hasPermission name="specimen:production:view">
	        <!-- 打版  -->
	        <div class="items clearfix">
	            <!-- 打版实际开始日 -->
	        	<div class="col-25 clearfix">
	                <p class="tit" style="width:75px;"><spring:message code="pecimenProduct_template_start_date"/></p>
	                <div class="timeBox">
                        <input type="text" class="laydate-icon" id="templateStartDate" name="templateStartDate" style="width: 110px" value="<fmt:formatDate value='${specimenProduction.templateStartDate}' pattern='yyyy-MM-dd' />" onclick="WdatePicker({el:this,dateFmt:'yyyy-MM-dd',onpicked:null})">
                    </div> 
	            </div>
	            <!-- 打版实际完成日 -->
	            <div class="col-25 clearfix">
	                <p class="tit" style="width:75px;"><spring:message code="pecimenProduct_template_end_date"/></p>
	                <div class="timeBox">
                        <input type="text" class="laydate-icon" id="templateEndDate" name="templateEndDate" style="width: 110px" value="<fmt:formatDate value='${specimenProduction.templateEndDate}' pattern='yyyy-MM-dd' />" data-rule-validateEndDate="#templateStartDate" onclick="WdatePicker({el:this,dateFmt:'yyyy-MM-dd',onpicked:null})">
                    </div> 
	            </div>
	            <!-- 打版所用工时 -->
	            <div class="col-25 clearfix">
	                <p class="tit"><spring:message code="pecimenProduct_template_costtime"/></p>
                    <input type="tel" style="width:100px;" id="templateCostTime" name="templateCostTime" value="<fmt:formatNumber value="${specimenProduction.templateCostTime}" pattern="#,##0.##"/>" onblur="formatNumber(this)" onfocus="unFormat(this)" data-rule-integerDecimalmax="12.2"  data-msg-integerDecimalmax="<spring:message code="pecimenProduct_pleaseInputPropertyNum"/>">
	            </div>
	            <!-- 打版人 -->
	            <div class="col-25 clearfix">
	                <p class="tit"><spring:message code="pecimenProduct_template_user"/></p>
	                <select style="width:100px;" id="makeId" name="makeId">
	                		<option value="">请选择</option>
	                        <c:forEach items="${specimenProduction.templateUserList}"   var="templateUser">
	                            <option <c:if test="${specimenProduction.makeId eq templateUser.id}">selected="selected"</c:if> value="${templateUser.id}" > 
	                                ${templateUser.firstNameEn}${templateUser.lastNameEn}
	                            </option>
	                        </c:forEach>
                    </select>
	            </div>
	        </div> 
	        </shiro:hasPermission>
	        </div>
	        <shiro:hasPermission name="specimen:production:view">
	        <!-- 打样  -->	        
	        <div class="items clearfix">
	            <!-- 打样实际开始日 -->
	        	<div class="col-25 clearfix">
	                <p class="tit" style="width:75px;"><spring:message code="pecimenProduct_sample_start_date"/></p>
	                <div class="timeBox">
                        <input type="text" class="laydate-icon" id="sampleStartDate" name="sampleStartDate" style="width: 110px" value="<fmt:formatDate value='${specimenProduction.sampleStartDate}' pattern='yyyy-MM-dd' />" onclick="WdatePicker({el:this,dateFmt:'yyyy-MM-dd',onpicked:null})">
                    </div> 
	            </div>
	            <!-- 打样实际完成日 -->
	            <div class="col-25 clearfix">
	                <p class="tit" style="width:75px;"><spring:message code="pecimenProduct_sample_end_date"/></p>
	                <div class="timeBox">
                        <input type="text" class="laydate-icon" id="sampleEndDate" name="sampleEndDate" style="width: 110px" value="<fmt:formatDate value='${specimenProduction.sampleEndDate}' pattern='yyyy-MM-dd' />" data-rule-validateEndDate="#sampleStartDate" onclick="WdatePicker({el:this,dateFmt:'yyyy-MM-dd',onpicked:null})">
                    </div> 	               
	            </div>
	            <!-- 打样所用工时 -->
	            <div class="col-25 clearfix">
	                <p class="tit"><spring:message code="pecimenProduct_template_costtime"/></p>
	                <input type="tel" style="width:100px;" id="sampleCostTime" name="sampleCostTime" value="<fmt:formatNumber value="${specimenProduction.sampleCostTime}" pattern="#,##0.##"/>" onblur="formatNumber(this)" onfocus="unFormat(this)" data-rule-integerDecimalmax="12.2"  data-msg-integerDecimalmax="<spring:message code="pecimenProduct_pleaseInputPropertyNum"/>">
	            </div>
                <!-- 打样人 -->	            
	            <div class="col-25 clearfix">
	                <p class="tit"><spring:message code="pecimenProduct_sample_user"/></p>
	                <input type="hidden" id="oldSamId" name="oldSamId" value="${specimenProduction.oldSamId}">
	                <select style="width:100px;" id="samId" name="samId">
	                <option value="">请选择</option>
	                        <c:forEach items="${specimenProduction.sampleUserList}"   var="sampleUser">
	                            <option <c:if test="${specimenProduction.samId eq sampleUser.id}">selected="selected"</c:if> value="${sampleUser.id}" > 
	                                ${sampleUser.firstNameEn}${sampleUser.lastNameEn}
	                            </option>
	                        </c:forEach>
                    </select>
	            </div>	            
	        </div>
	        </shiro:hasPermission>
	        <shiro:hasPermission name="specimen:production:view">
	        <!-- 成本 -->	        
	        <div class="items clearfix">
	            <!-- 物料费用 -->
	        	<div class="col-25 clearfix">
	                <p class="tit" style="width:75px;"><spring:message code="pecimenProduct_sample_material_cost"/></p>
	                <input type="tel" style="width:110px;" id="sampleMaterialCost" name="sampleMaterialCost" readonly="readonly" value="<fmt:formatNumber value="${specimenProduction.sampleMaterialCost}" pattern="#,##0.##"/>">
	            </div>
	            <!-- 人员费用 -->
	            <div class="col-25 clearfix">
	                <p class="tit" style="width:75px;"><spring:message code="pecimenProduct_sample_manday_cost"/></p>
	                <input type="tel" style="width:110px;" id="sampleMandayCost" name="sampleMandayCost" value="<fmt:formatNumber value="${specimenProduction.sampleMandayCost}" pattern="#,##0.##"/>" onblur="formatMoney(this,2)" onfocus="unFormat(this)" data-rule-integerDecimalmax="12.2"  data-msg-integerDecimalmax="<spring:message code="pecimenProduct_pleaseInputPropertyNum"/>" onchange="addCost()">
	            </div>
	            <!-- 其他费用 -->
	            <div class="col-25 clearfix">
	                <p class="tit"><spring:message code="pecimenProduct_sample_other_cost"/></p>
	                <input type="tel" style="width:100px;" id="sampleOtherCost" name="sampleOtherCost" value="<fmt:formatNumber value="${specimenProduction.sampleOtherCost}" pattern="#,##0.##"/>" onblur="formatMoney(this,2)" onfocus="unFormat(this)" data-rule-integerDecimalmax="12.2"  data-msg-integerDecimalmax="<spring:message code="pecimenProduct_pleaseInputPropertyNum"/>" onchange="addCost()">
	            </div>
	            <!-- 合计单价 -->
	            <div class="col-25 clearfix">
	                <p class="tit"><spring:message code="pecimenProduct_sample_cost"/></p>
	                <p><input type="tel" style="width:100px;" id="sampleCost" name="sampleCost" readonly="readonly" value="<fmt:formatNumber value="${specimenProduction.sampleCost}" pattern="#,##0.##"/>"></p>
	            </div>	            
	        </div>
	        </shiro:hasPermission>
	        <!-- 备注 --> 	        
	        <div class="items clearfix">
	        	<p class="tit"><spring:message code="pecimenProduct_remark"/></p>
	            <textarea id="sampleRemark" name="sampleRemark" style="width:770px;height:340px;" >${specimenProduction.sampleRemark}</textarea>
	        </div> 
		</div>
    </div>
    </div>
    </form>
</body>
</html>